package com.hgvip.controller;

import com.hgvip.common.entity.ResponseData;
import com.hgvip.entity.User;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by arnold.zhu on 2017/7/31.
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @ApiOperation(value = "获取用户列表", notes = "获取所有用户列表", produces = "application/json")
    @RequestMapping(value = "", method = RequestMethod.GET)
    public ResponseData getUserList() {
        List<User> users = new ArrayList<>();
        return new ResponseData(200, "查询成功!", users);
    }

    @ApiOperation(value = "获取用户详细信息", notes = "根据userId获取用户详细信息", produces = "application/json")
    @ApiResponses(value = {
            @ApiResponse(code = 405, message = "Invalid input", response = Integer.class),
            @ApiResponse(code = 400, message = "Bad Request", response = Integer.class)
    })
    @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "int", paramType = "path")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ResponseData getUser(@PathVariable int id) {
        return new ResponseData(200, "查询成功!", new User(id, "zhangsan", 22, 1));
    }

    @ApiOperation(value = "创建用户", notes = "根据请求信息创建用户")
    @ApiImplicitParam(name = "user", value = "用户实体", required = true, dataType = "User", paramType = "body")
    @RequestMapping(value = "", method = RequestMethod.POST)
    public ResponseData addUser(@RequestBody User user) {
        return new ResponseData(200, "添加成功!", user);
    }

    @ApiOperation(value = "更新用户详细信息", notes = "更新指定用户详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "int", paramType = "path"),
            @ApiImplicitParam(name = "user", value = "用户信息", required = true, dataType = "User", paramType = "body"),
            @ApiImplicitParam(name = "x-transaction-id", value = "交易ID", dataType = "String", paramType = "header"),
    })
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public ResponseData updateUserName(@PathVariable int id, @RequestBody User user) {
        return new ResponseData(200, "更新成功!", user);
    }

    @ApiOperation(value = "删除用户", notes = "根据url的id来指定删除对象")
    @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "int", paramType = "path")
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public ResponseData deleteUser(@PathVariable int id) {
        return new ResponseData(200, "删除成功!", id);
    }

}
